<?php
namespace Admin\Model;
use Think\Model;
use Admin\Model\OptionModel;

/**
* Created by hanquan.
* User Adminstrator
* Date Date 2017/3/26
* Time 23:43
* OptionCategoryModel 手机选项分类类
*/

class OptionCategoryModel extends Model
{
	private $OptionCategory = null;

	function __construct()
	{
		parent::__construct();
		$this->OptionCategory = M('OptionCategory');
	}

	/*
	* 获取选项分类
	*/
	public function get_option_category($vid){

		$condition['vid'] = $vid;
		return $this->OptionCategory->field('cid,c_name,c_require,c_radio')->where($condition)->select();
	}

	/**
     * 插入或修改选项分类
     * @data 提交选项分类的数据
     * @cid 选项分类id
     */
	public function set_option_category($data,$cid=FALSE){

		if(!$cid){
			return $this->OptionCategory->add($data);
		}else{
			$condition['cid'] = $cid;
			return $this->OptionCategory->where($condition)->save($data);
		}
	}

	/**
     * 删除选项分类
     * @cid 选项分类id
     */
	public function del_option_category($cid){

		$condition['cid'] = $cid;
		$Option = new OptionModel();
		$Option->table('mp_option')->where($condition)->delete();
		return $this->OptionCategory->where($condition)->delete();
	}
}